<template>
  <div idm-ctrl="idm_module"
  :id="moduleObject.id"
  :idm-ctrl-id="moduleObject.id"
  class="remindbox">
    <div class="remind-center" v-if="dialogVisible">
      
    </div>
  </div>
</template>

<script>
export default {
  name: 'IremindDialog',
  data () {
    return {
      dialogVisible: true,
      moduleObject: {},
      pageObj: {},
      propData: this.$root.propData.compositeAttr || {}
    }
  },
  mounted() {
    this.moduleObject = this.$root.moduleObject;
    this.init()
  },
  methods: {
    handleStyle () {
      let styleObject = {};
      for (const key in this.propData) {
        if (this.propData.hasOwnProperty.call(this.propData, key)) {
          const element = this.propData[key]
          if (!element && element !== false && element != 0) {
            continue
          }
          switch (key) {
            case 'width':
              styleObject['width'] = element;
              break
            case 'height':
              styleObject['height'] = element;
              break
            case 'ulbox':
              IDM.style.setBoxStyle(styleObject, element);
              break
            case 'bgbox':
              if (this.pageObj[this.propData.backgroundField]) {
                let bg = this.pageObj[this.propData.backgroundField];
                styleObject['background'] = `url(${IDM.url.getWebPath(bg)}) no-repeat`;
                styleObject['background-size'] = '100% 100%';
              } else {
                styleObject['background'] = `url(${IDM.url.getWebPath(element)}) no-repeat`;
                styleObject['background-size'] = '100% 100%';
              }
              break
            case 'bgColor':
              styleObject['background-color'] = element && element.hex8;
              break
            case 'boxShadow':
              styleObject['box-shadow'] = element;
              break
            case 'boxBorder':
              IDM.style.setBorderStyle(styleObject, element);
              break
            case 'dialogIndex':
              styleObject['z-index'] = element;
              break
          }
        }
      }
      window.IDM.setStyleToPageHead(this.moduleObject.id + " .remind-center", styleObject);
    },
    /**
     * 调用IDM提供的内置关闭方法
    */
    closeMyDialog(isOk) {
      window.IdmBuiltin_CloseDialog({
        targetModule: [{ moduleId: this.moduleObject.packageid, moduleName: this.moduleObject.asName }],
        isOkEvent: isOk
      })
    },
    /**
     * 调用IDM提供的内置打开方法
    */
    openMyDialog(isOk) {
      window.IdmBuiltin_OpenDialog({
        targetModule: [{ moduleId: this.moduleObject.packageid, moduleName: this.moduleObject.asName }],
        isOkEvent: isOk
      })
    },
    // 过滤接口参数
    fileterParams() {
      let obj = {};
      if (this.propData.customFunc && this.propData.customFunc.length > 0) {
        let name = this.propData.customFunc[0].name
        obj = window[name] && window[name].call(this);
      }
      return obj
    },
    initData () {
      if (this.moduleObject.env == "production") {
        if (this.propData.dataSource && this.propData.dataFlag) {
          const routerParams = this.fileterParams();
          IDM.datasource.request(this.propData.dataSource[0]?.id, {
            moduleObject: this.moduleObject,
            param: { ...routerParams }
          }, (data) => {
            if (data) {
              this.pageObj = data;
              this.dialogVisible = this.pageObj[this.propData.showDialog];

              if (this.dialogVisible) {
                this.openMyDialog();
              } else {
                this.closeMyDialog();
              }
            }
          })
        }
      } else {
        this.dialogVisible = true;
        this.openMyDialog();
      }
    },
    init () {
      console.log(this.propData, '数据源');
      this.handleStyle();
      this.initData();
    }
  }
}
</script>
